package com.android.update.tool;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ViewUtils {

    public static List<TextView> findTextViews(View view) {
        List<TextView> textViews = new ArrayList<>();
        if (view instanceof TextView) {
            textViews.add((TextView) view);
            return textViews;
        }
        if (view instanceof ViewGroup) {
            parView(textViews, (ViewGroup) view);
            return textViews;
        }
        return textViews;
    }

    /**
     * 解析控件
     *
     * @param textViews
     * @param view
     */
    private static void parView(List<TextView> textViews, ViewGroup view) {
        int lenght = view.getChildCount();
        for (int i = 0; i < lenght; i++) {
            View v = view.getChildAt(i);
            if (v instanceof TextView) {
                textViews.add((TextView) v);
                continue;
            }
            if (v instanceof ViewGroup) {
                parView(textViews, (ViewGroup) v);
            }
        }
    }
}
